/*
 * (C) Copyright 2013 George Daswani (georgedaswani@gmail.com) and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *    George Daswani (georgedaswani@gmail.com)
 */

package am.api.model;

import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

public class AMCredential implements Serializable {

	private static AMCredential defaultCredential;
	private final static long serialVersionUID = 1L;

	public static synchronized AMCredential getDefaultCredential() {
		if (defaultCredential == null) {
			defaultCredential = new AMCredential("CloudORA92", "Admin",
					"amsndadm");

		}
		return defaultCredential;
	}

	private final String database;

	private final String password;

	private final String userName;

	public AMCredential(String database, String userName, String password) {
		super();
		this.database = database;
		this.userName = userName;
		this.password = password;
	}

	public String getDatabase() {
		return database;
	}

	public String getPassword() {
		return password;
	}

	public String getUserName() {
		return userName;
	}

	public int hashCode() {
		return new HashCodeBuilder(1, 3).append(database).append(userName)
				.append(password).toHashCode();
	}

	public String toString() {
		return new ToStringBuilder(this).append("database", database)
				.append("userName", userName).append("password", "*******")
				.toString();
	}

	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}
		AMCredential rhs = (AMCredential) obj;
		return new EqualsBuilder().append(database, rhs.database)
				.append(userName, rhs.userName).append(password, rhs.password)
				.isEquals();
	}
}
